/**
 * 
 */
package mblog.core.persist.dao.impl;

import java.util.List;

import mblog.core.persist.dao.UserDao;
import mtons.modules.persist.impl.DaoImpl;
import mtons.modules.pojos.Page;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.faxsun.core.persist.entity.UserPO;

/**
 * @author langhsu
 *
 */
public class UserDaoImpl extends DaoImpl<UserPO>implements UserDao {
	private static final long serialVersionUID = -3396151113305189145L;

	public UserDaoImpl() {
		super(UserPO.class);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
	public UserPO get(String username) {
		return findUniqueBy("username", username);
	}

	@Override
	public List<UserPO> paging(Page page) {
		PagingQuery<UserPO> q = pagingQuery(page);
		q.desc("id");
		return q.list();
	}

	@Override
	public UserPO get(long uid) {
		return findUniqueBy("id", uid);
	}

	@Override
	@Transactional
	public UserPO getByUserId(long userId) {
		return findUniqueBy("userId", userId);
	}

	@Override
	@Transactional
	public void save(Object entity) {
		super.save(entity);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
	public UserPO getByToken(String token) {
		return findUniqueBy("token", token);
	}

	@Override
	@Transactional
	public void update(UserPO user) {
		super.update(user);
	}

	@Override
	public UserPO getByThirdId(String openId) {
		return findUniqueBy("thirdLogin", openId);
	}

	@Override
	public UserPO getByUnionId(String unionId) {
		return findUniqueBy("wechatUnionId", unionId);
	}
}
